package com.medusa.aps.business.modules.basic.mp.entity;

import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.medusa.aps.business.model.BaseEntity;
import com.medusa.aps.business.common.mp.FastJson2TypeHandler;
import com.medusa.aps.business.common.mp.IFastJson2TypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * 班制实体类
 *
 * @author yuxh
 * @since 2023-08-14 17:37:43
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@TableName(value = "class_system", autoResultMap = true)
public class ClassSystem extends BaseEntity<ClassSystem> {
    /**
     * 主键
     */
    @Schema(description = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 工作时段Id
     */
    @Schema(description = "工作时段Id，下标周一到周日")
    @TableField(typeHandler = FastJson2TypeHandler.class)
    private List<Integer> periodIds;
    /**
     * 设备组id集合
     */
    @Schema(description = "设备组id集合")
    @TableField(typeHandler = DeviceIdsTypeHandler.class)
    private Set<Long> deviceIds;

    /**
     * 获取主键值
     *
     * @return 主键值
     */
    @Override
    public Serializable pkVal() {
        return this.id;
    }

    /**
     * 设备组id集合类型处理器
     */
    public static class DeviceIdsTypeHandler extends IFastJson2TypeHandler {
        @Override
        protected TypeReference<Set<Long>> getTypeReference() {
            return new TypeReference<>() {
            };
        }
    }
}

